Intro

model-viewer

This package wraps the excellent web component <model-viewer> to make it easier to use/consume in toddle apps.

The model-viewer allows users to interact with complex 3D models provided as .glb or .gltf files.

Demo

Try picking different models below

You can find more models here

Components

  • model-viewer

    The main component that wraps the web component <model-viewer>. It doesn't expose everything from the original API for now. See available attributes and events below.

    Attributes

    srcDocsURL to the .glb or .gltf file
    altDocsText for screen readers as an alternative representation of the 3D model.
    posterDocsAn image URL for an image to display until the model is loaded and rendered.
    loadingDocsLoading strategy for the model. Can be "auto", "lazy" or "eager" - defaults to "auto"
    with-credentialsDocsUses cookies when fetching the 3D model from the "src" attribute
    disable-panDocsDisables panning
    disable-tapDocsDisables tapping
    disable-zoomDocsDisables zoom
    auto-rotateDocsAutomatically rotates the 3D model
    auto-fitSets width and height to 100% of the <model-viewer> element

    Events

    errorDocsEvent that indicates an error happened - for instance if the 3D model couldn't be loaded
    loadDocsFires when the model has been loaded

Formulas

  • getDimensions

    Returns the dimensions (x, y, z) of the loaded 3D model

    Docs

    Arguments

    idid of the model-viewer instance
  • toDataUrl

    Returns a dataUrl for a screenshot of the model viewer

    Docs

    Arguments

    idid of the model-viewer instance